package club.baimahu.pencil.domain.entity.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class LocationTreeNode extends AbstractTreeNode{

    private String nodeName;
    private Long nodeId;
    private List<TreeNode> children;
    private TreeNode parentTreeNode;

    public LocationTreeNode(){}

    public LocationTreeNode(Long nodeId,String nodeName){
        this.nodeId = nodeId;
        this.nodeName = nodeName;
    }

    @Override
    public void setParentTreeNode(TreeNode parentTreeNode){
        this.parentTreeNode = parentTreeNode;
    }

    @Override
    public void addChildTreeNode(TreeNode treeNode) {
        children = Optional.ofNullable(children).orElse(new ArrayList<>());
        children.add(treeNode);
        treeNode.setParentTreeNode(this);
    }


    @Override
    public String nodeName() {
        return this.nodeName;
    }

    @Override
    public Long nodeId() {
        return this.nodeId;
    }

    @Override
    public List<TreeNode> children() {
        return this.children;
    }


    public static void main(String[] args) {
        new LocationTreeNode(2L,"1111").addChildTreeNode(new LocationTreeNode(1L,"1"));
    }
}
